import {message} from 'antd';
import {formatMessage} from './intl';

export const newOrUpdateValidator = (data, details) => {
    const requiredFields = [];
    if(!data || !data.brandId)
        requiredFields.push(
            formatMessage({
                id: 'validator.brandId',
                defaultMessage: '品牌'
            })
        );
    if(!data || !data.dutyUnitId)
        requiredFields.push(
            formatMessage({
                id: 'validator.dutyUnitId',
                defaultMessage: '供应商'
            })
        );
    if(!data || !data.partId)
        requiredFields.push(
            formatMessage({
                id: 'validator.partId',
                defaultMessage: '原备件'
            })
        );
    if(!data || !data.replacedPartId)
        requiredFields.push(
            formatMessage({
                id: 'validator.replacedPartId',
                defaultMessage: '替换备件'
            })
        );
    if(requiredFields.length > 0) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.requied',
            defaultMessage: '必填'
        })}`);
        return false;
    }
    if(details.length <= 0) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.details',
            defaultMessage: '清单不能为空'
        })}`);
        return false;
    }
    return true;
};
